import http from '@/Services/Request'

const base = '/api/Users'

export default {
    /** 获取所有用户 */
    GetAll() {
        return http.get(base)
    },

    /** 根据ID获取用户 */
    GetById(id) {
        return http.get(`${base}/${id}`)
    },

    /** 检查学号是否已存在 */
    CheckStudentId(studentId) {
        return http.get(`${base}/check/studentId/${studentId}`)
    },

    /** 检查昵称是否已存在 */
    CheckNickname(nickname) {
        return http.get(`${base}/check/nickname/${nickname}`)
    },

    /** 检查手机号是否已存在 */
    CheckPhone(phone) {
        return http.get(`${base}/check/phone/${phone}`)
    },

    /** 创建用户 */
    Create(model) {
        return http.post(base, model)
    },

    /** 更新用户 */
    Update(id, model) {
        return http.put(`${base}/${id}`, model)
    },

    /** 更新用户昵称 */
    UpdateNickname(userId, nickname) {
        return http.put(`${base}/${userId}/nickname?nickname=${nickname}`)
    },

    /** 更新用户手机号 */
    UpdatePhone(userId, phone) {
        return http.put(`${base}/${userId}/phone?phone=${phone}`)
    },

    /** 更新用户密码 */
    UpdatePassword(userId, oldPassword, newPassword) {
        return http.put(`${base}/${userId}/password?oldPassword=${oldPassword}&newPassword=${newPassword}`)
    },

    /** 更新用户头像 */
    UpdateAvatar(userId, avatar) {
        return http.put(`${base}/${userId}/avatar?avatar=${avatar}`)
    },

    /** 删除用户 */
    Delete(userId) {
        return http.delete(`${base}/${userId}`)
    },

    /** 用户登录 */
    Login(model) {
        return http.post(`${base}/login`, model)
    },

    /** 用户注册 */
    Register(model) {
        return http.post(`${base}/register`, model)
    },

    /** 获取用户收藏 */
    GetFavorites(userId) {
        return http.get(`${base}/${userId}/favorites`)
    },

    /** 添加收藏 */
    AddFavorite(userId, productId) {
        return http.post(`${base}/${userId}/favorites/${productId}`)
    },

    /** 取消收藏 */
    RemoveFavorite(userId, productId) {
        return http.delete(`${base}/${userId}/favorites/${productId}`)
    }
} 